import { getuser } from '../../utils/storage'
import { request, wxlogin } from '../../utils/https'
import { getschoolannouncementpushbyid } from '../../utils/interfaces'
import * as moment from 'moment'
export default {
  data () {
    return {
      time: '',
      announcement: {
        title: '',
        text: ''
      }
    }
  },
  async onLoad (option) {
    const { ID } = await getuser('user')
    try {
      let code = await wxlogin()
      const data = await request(getschoolannouncementpushbyid, {
        data: {
          schoolstudentid: ID,
          code,
          ID: option.ID
        }
      })
      this.time = moment(data.createdAt).format('YYYY-MM-DD hh:mm')
      this.announcement = data
    } catch (err) {
      console.log(err)
      // wx.showModal({
      //   title: "提示",
      //   content: "服务器请求失败，点击确定重新加载",
      //   success: res => {
      //     if (res.confirm) {
      //       this.start();
      //     } else if (res.cancel) {
      //       console.log("用户点击取消");
      //     }
      //   }
      // });
    }
  }
}
